/* eslint-disable no-console */
export class List {
	data: number[] = []

	search(key: number): number | undefined {
		return this.data.find((value) => {
			if (value === key) {
				return value
			}
			return undefined
		})
	}

	insert(x: number): void {
		this.data.push(x)
	}

	delete(x: number) {
		const newData: number[] = []
		this.data.forEach((value) => {
			if (value !== x) {
				newData.push(value)
			}
		})
		this.data = newData
	}
}

const s = new List()

s.insert(3)
s.insert(2)
s.insert(1)
console.log(s.search(2))
console.log(s.data)
s.delete(2)
console.log(s.data)
console.log(s.search(2))
